﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.Reflection;

// 1)  Add reference to the cli library and include the namespace
using Idlesoft.Cli; 

namespace TestApp
{

	class Program
	{
		public const string PERSON_TITLE = "Person Demo";
		public const string PERSON_DESC = "A demonstration of the Cli api.  Supply your name and age...";

		public const string CALCULATOR_TITLE = "Calculator Demo";
		public const string CALCULATOR_DESC = "A demonstration of the Cli api.  The operation and two values can be specified";

		public static readonly string[] PERSON_ARGS = new string[] { "--name", "Scott", "--age", "37", "donkey", "--pets", "Penny", "Triton", "--saveconfig", "save.xml" };
		public static readonly string[] CALCULATOR_ARGS = new string[] { "--numbers", "13", "37", "-8", "--op", "+" };

		static void Main(string[] args)
		{
			try
			{
				// 3)  Make call to CliBuilder.Create early on in your code to parse commandline args and populate your decorated class object
				var person = CliBuilder.Create<Person>(PERSON_TITLE, PERSON_DESC, FlagTypes.Default, PERSON_ARGS);  //<-- try replacing PERSON_ARGS with args or removing it all together
				var count = person.Pets != null ? person.Pets.Length : 0;
				var pets = person.Pets.Aggregate("", (curr, next) => curr + " " + next) ?? "";

				// 4)  Use the class object with populated properties
				Console.WriteLine(string.Format("My name is {0} and I am {1} years old.  I have {2} pets: {3}.", person.Name, person.Age, count, pets));

				//And that's it!  There are many options to learn, but these are the basics!  Enjoy!

				//here is another example using a calculator
				var calculator = CliBuilder.Create<Calculator>(CALCULATOR_TITLE, CALCULATOR_DESC, FlagTypes.Default, CALCULATOR_ARGS); //<-- try replacing CALCULATOR_ARGS with args or removing it all together
				Console.WriteLine(string.Format("Calculation: Numbers ={0} Op = '{1}' Result = {2}", calculator.Numbers.Aggregate("", (curr, next) => curr + " " + next), calculator.Op, calculator.Calculate()));
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}
	}
}
